/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

//import connectivity.QueryManager;
import connectivity.QueryManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import java.text.DecimalFormat;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import main.BarApplication;
import model.Category;

import model.Product;
import model.mainCategory;

public class shopping_bar extends javax.swing.JPanel implements MouseListener, ActionListener {

    private int categoryId = 0;
    private final int verticalPosition = 60;
    private final int offset = 40;
    private JButton left, right;
    private JLabel label;
    private JPanel buttonPanel;
    private int vestiging = 1;
    private LoginScreen login;

    public shopping_bar(LoginScreen login) {
       
        initComponents();
        this.login = login;
        basketDisplay();
        unfold();
    }

    private void unfold() {
        for (int i = 0; i < jTree1.getRowCount(); i++) {
            jTree1.expandRow(i);
        }
    }

    // Read the data from the database and create a tree view.
    // For every category add a new tree and in that tree add a subcategory
    public DefaultMutableTreeNode getData() {
        QueryManager queryManager = BarApplication.getQueryManager();
        List<mainCategory> mainCategories = queryManager.getMainCategories();


        // Main Tab
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Categorie");

        // Here you will get the main "Tree" with the maincategories in first sight
        for (int i = 0; i < mainCategories.size(); i++) {
            mainCategory mainCategory = mainCategories.get(i);
            int mainCategoryId = mainCategory.getMainCategoryId();

            DefaultMutableTreeNode cat = new DefaultMutableTreeNode(mainCategory.getName());
            List<Category> categories = queryManager.getCategories(mainCategoryId);

            // This will read the subcategory from the main category
            // Important for database.. make sure the maincategory is matching the subcategory
            for (int x = 0; x < categories.size(); x++) {
                Category category = categories.get(x);
                DefaultMutableTreeNode catAdd = new DefaultMutableTreeNode(category.getName());

                cat.add(catAdd);

            }
            root.add(cat);
        }

        return root;
    }

    // As soon as the user clicks on the subcategory, the user will see the products in the middle panel
    // The parameter in the below method contains the "subcategoryId" that will be used to pull the products out of the database
    // First the label will be made. then the name will be added, the description will then be added
    // Following is the currency (price) of the product. Last you will see the order button "Bestel" to put it in the basket
    private void addProduct(int categoryid) {
        this.categoryId = categoryid;
        String vestigingNaam = "";
        if (vestiging == 1) {
            vestigingNaam = "Purmerend";
        }
        if (vestiging == 2) {
            vestigingNaam = "Alkmaar";
        }
        if (vestiging == 3) {
            vestigingNaam = "Haarlem";
        }

        JLabel vestigingPlaats = new JLabel("Vestinging: " + vestigingNaam);
        vestigingPlaats.setBounds(35, 0, 340, 15);
        vestigingPlaats.setFont(BarApplication.FONT_12_BOLD);
        vestigingPlaats.setName("vestigingPlaats");

        jPanel_ProductList.add(vestigingPlaats);

        // if the categoryId is 8 then it should add the course to the productview
        if (categoryId == 8) {
            List<Product> cursus = BarApplication.getQueryManager().getCurses(vestiging);
            DecimalFormat df = new DecimalFormat("#0.00");

            int width = jPanel_ProductList.getWidth();
 
            JLabel cursusnaam = new JLabel("Cursus Naam");
            cursusnaam.setBounds(35, 15, 340, 20);
            cursusnaam.setFont(BarApplication.FONT_12_BOLD);
            cursusnaam.setName("Cursus Naam");
            jPanel_ProductList.add(cursusnaam);

            JLabel datumtijd = new JLabel("Datum en Tijd");
            datumtijd.setBounds((width / 4) + 15, 15, 340, 20);
            datumtijd.setFont(BarApplication.FONT_12_BOLD);
            datumtijd.setName("Datum en Tijd");
            jPanel_ProductList.add(datumtijd);

            JLabel plaatsen = new JLabel("Beschikbaar");
            plaatsen.setBounds(width / 2, 15, 340, 20);
            plaatsen.setFont(BarApplication.FONT_12_BOLD);
            plaatsen.setName("Beschikbare Plaatsen");
            jPanel_ProductList.add(plaatsen);

            JLabel prijs = new JLabel("Prijs");
            prijs.setBounds((width / 2) + 100, 15, 80, 20);
            prijs.setFont(BarApplication.FONT_12_BOLD);
            prijs.setName("Prijs");
            jPanel_ProductList.add(prijs);

            for (int i = 0; i < cursus.size(); i++) {
                Product course = cursus.get(i);

                //         int width = jPanel_ProductList.getWidth();
                //          JLabel lblDot = new JLabel("\u2022");
                //         lblDot.setFont(BarApplication.FONT_12_BOLD);
                //        lblDot.setBounds(20, verticalPosition + i * offset, 10, 20);
                //       jPanel_ProductList.add(lblDot);

                JLabel lblProduct = new JLabel(course.getName());
                lblProduct.setBounds(10, verticalPosition + i * offset, 340, 20);
                lblProduct.setFont(BarApplication.FONT_10_PLAIN);
                lblProduct.setName(String.valueOf(course.getProductId()));
                jPanel_ProductList.add(lblProduct);

                JLabel lblDescription = new JLabel(course.getcBeginD() + " - " + course.getcTijd());
                lblDescription.setBounds(width / 4, verticalPosition + i * offset, 340, 20);
                lblDescription.setFont(BarApplication.FONT_10_PLAIN);
                jPanel_ProductList.add(lblDescription);

                JLabel lblTotal = new JLabel(Integer.toString(course.remainingA()));
                lblTotal.setBounds(width / 2 + 50, verticalPosition + i * offset, 340, 20);
                lblTotal.setFont(BarApplication.FONT_10_PLAIN);
                jPanel_ProductList.add(lblTotal);

                JLabel lblPrice = new JLabel(BarApplication.CURRENCY + df.format(course.getcPrijs()));
                lblPrice.setBounds(width / 2 + 100, verticalPosition + i * offset, 80, 20);
                lblPrice.setFont(BarApplication.FONT_10_PLAIN);
                jPanel_ProductList.add(lblPrice);
                
                System.out.println(Integer.toString(course.remainingA()));
                if (course.remainingA() > 0){
                JButton btnOrder = new JButton("Bestel");
                btnOrder.setBounds(width - 80, verticalPosition + i * offset, 70, 20);
                btnOrder.setFont(BarApplication.FONT_10_PLAIN);
                btnOrder.setName(String.valueOf(course.getProductId()));
                btnOrder.addActionListener(this);       // addActionListener to read when the user clicks the button
                jPanel_ProductList.add(btnOrder);
                }
            }

        } else {



            List<Product> products = BarApplication.getQueryManager().getProducts(categoryId);
            DecimalFormat df = new DecimalFormat("#0.00");


            for (int i = 0; i < products.size(); i++) {
                Product product = products.get(i);

                int width = jPanel_ProductList.getWidth();
                JLabel lblDot = new JLabel("\u2022");
                lblDot.setFont(BarApplication.FONT_12_BOLD);
                lblDot.setBounds(20, verticalPosition + i * offset, 10, 20);
                jPanel_ProductList.add(lblDot);

                JLabel lblProduct = new JLabel(product.getName());
                lblProduct.setBounds(35, verticalPosition + i * offset, 340, 20);
                lblProduct.setFont(BarApplication.FONT_12_BOLD);
                lblProduct.setName(String.valueOf(product.getProductId()));
                //    lblProduct.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                //    lblProduct.addMouseListener(this);
                jPanel_ProductList.add(lblProduct);
                
     // get the description for the faciliteiten table
                JLabel lblDescription = new JLabel(product.getDescription());
                lblDescription.setBounds(35, verticalPosition + i * offset + 15, 340, 20);
                lblDescription.setFont(BarApplication.FONT_10_PLAIN);
                jPanel_ProductList.add(lblDescription);
     // ends here
                
                JLabel lblPrice = new JLabel(BarApplication.CURRENCY + df.format(product.getPrice()));
                lblPrice.setBounds(width - 200, verticalPosition + i * offset, 80, 20);
                lblPrice.setFont(BarApplication.FONT_12_BOLD);
                jPanel_ProductList.add(lblPrice);

                JButton btnOrder = new JButton("Bestel");
                btnOrder.setBounds(width - 130, verticalPosition + i * offset, 90, 20);
                btnOrder.setFont(BarApplication.FONT_12_BOLD);
                btnOrder.setName(String.valueOf(product.getProductId()));
                btnOrder.addActionListener(this);       // addActionListener to read when the user clicks the button
                jPanel_ProductList.add(btnOrder);
            }
            categoryId = 0;
        }
    }

    // When the basket is first created it will remove all products from the basket (jLabel1)
    // First it will add the "-" sign so that the user can click on "Less" 
    // Then the product will be added and then the price
    // Underneath the product list you will get a grand total
    // In the bottom of the tool you will get two buttons: "Totaal and Annuleren"
    private void basketDisplay() {
        jLabel1.removeAll();
        model.Basket basket = BarApplication.getBasket();

        DecimalFormat df = new DecimalFormat("#0.00");

        int verticalPosition = 10;

        for (Product product : basket.getProducts()) {
            JButton lblButton = new JButton("-");
            lblButton.setBounds(0, verticalPosition, 38, 20);
            lblButton.setFont(BarApplication.FONT_10_PLAIN);
            lblButton.setName(String.valueOf(product.getProductId()) + "less");
            lblButton.addActionListener(this);     // Listener for the "-" button
            jLabel1.add(lblButton);

            JLabel lblProduct = new JLabel(basket.getProductAmount(product)
                    + " - " + product.toString());
            lblProduct.setBounds(40, verticalPosition, 130, 20);
            lblProduct.setFont(BarApplication.FONT_10_PLAIN);
            jLabel1.add(lblProduct);

            JLabel lblPrice = new JLabel(BarApplication.CURRENCY + df.format(product.getPrice()));
            lblPrice.setBounds(170, verticalPosition, 150, 20);
            lblPrice.setFont(BarApplication.FONT_10_PLAIN);
            jLabel1.add(lblPrice);



            verticalPosition += 20;
        }

        JLabel lblTotal = new JLabel("Total: ");
        lblTotal.setBounds(5, verticalPosition, 50, 20);
        lblTotal.setFont(BarApplication.FONT_10_BOLD);
        jLabel1.add(lblTotal);

        JLabel lblTotalPrice = new JLabel(BarApplication.CURRENCY + df.format(basket.getTotalCosts()));
        lblTotalPrice.setBounds(170, verticalPosition, 50, 20);
        lblTotalPrice.setFont(BarApplication.FONT_10_BOLD);
        jLabel1.add(lblTotalPrice);

        int btnOffset = jLabel1.getHeight() - 25;
        JButton btnGoToPay = new JButton("Betalen");
        btnGoToPay.setBounds(5, btnOffset, 110, 20);
        btnGoToPay.setName("pay");
        btnGoToPay.setFont(BarApplication.FONT_12_BOLD);
        btnGoToPay.addActionListener(this);     // Listener for the "Betalen" button
        /*    if (basket.size() <= 0) {
         btnGoToPay.setEnabled(false);
         }
         */ jLabel1.add(btnGoToPay);

        int width = jLabel1.getWidth();
        JButton btnCancelOrder = new JButton("Annuleren");
        btnCancelOrder.setName("cancel");
        btnCancelOrder.setBounds(width - 125, btnOffset, 110, 20);
        btnCancelOrder.setFont(BarApplication.FONT_12_BOLD);
        btnCancelOrder.addActionListener(this);     // Listener for the "Annuleren" button
        /*    if (basket.size() <= 0) {
         btnCancelOrder.setEnabled(false);
         }
         */ jLabel1.add(btnCancelOrder);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel_CategoryList = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jCheckBox2 = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        jCheckBox3 = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jPanel_ProductList = new javax.swing.JPanel();
        jPanel_bestelling = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        home = new javax.swing.JLabel();
        leden = new javax.swing.JLabel();
        activiteit = new javax.swing.JLabel();
        bar = new javax.swing.JLabel();
        factuur = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        jPanel_CategoryList.setBackground(new java.awt.Color(255, 255, 255));
        jPanel_CategoryList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(null, "Kies een Categorie", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(0, 51, 204)))); // NOI18N

        jTree1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jTree1.setModel(new DefaultTreeModel(getData())
        );
        jTree1.setShowsRootHandles(true);
        jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTree1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTree1);

        jLabel2.setText("Purmerend");

        jCheckBox1.setSelected(true);
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Alkmaar");
        jLabel3.setToolTipText("");

        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jLabel4.setText("Haarlem");

        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Vestiging");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addComponent(jCheckBox2)
                            .addComponent(jCheckBox3))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox3)
                    .addComponent(jLabel4))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel_CategoryListLayout = new javax.swing.GroupLayout(jPanel_CategoryList);
        jPanel_CategoryList.setLayout(jPanel_CategoryListLayout);
        jPanel_CategoryListLayout.setHorizontalGroup(
            jPanel_CategoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_CategoryListLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_CategoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        jPanel_CategoryListLayout.setVerticalGroup(
            jPanel_CategoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_CategoryListLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel_ProductList.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel_ProductList.setToolTipText("");
        jPanel_ProductList.setAutoscrolls(true);

        javax.swing.GroupLayout jPanel_ProductListLayout = new javax.swing.GroupLayout(jPanel_ProductList);
        jPanel_ProductList.setLayout(jPanel_ProductListLayout);
        jPanel_ProductListLayout.setHorizontalGroup(
            jPanel_ProductListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 540, Short.MAX_VALUE)
        );
        jPanel_ProductListLayout.setVerticalGroup(
            jPanel_ProductListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel_bestelling.setBackground(new java.awt.Color(255, 255, 255));
        jPanel_bestelling.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bestelling", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(0, 51, 204))); // NOI18N

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/17449529-3d-white-people-with-a-shopping-cart-isolated-white-background-3d-image.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel_bestellingLayout = new javax.swing.GroupLayout(jPanel_bestelling);
        jPanel_bestelling.setLayout(jPanel_bestellingLayout);
        jPanel_bestellingLayout.setHorizontalGroup(
            jPanel_bestellingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_bestellingLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel_bestellingLayout.setVerticalGroup(
            jPanel_bestellingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_bestellingLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addContainerGap())
        );

        home.setText("Home");
        home.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        home.setFocusCycleRoot(true);
        home.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                homeMouseClicked(evt);
            }
        });

        leden.setText("Leden");
        leden.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        leden.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ledenMouseClicked(evt);
            }
        });

        activiteit.setText("Activiteit");
        activiteit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        activiteit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                activiteitMouseClicked(evt);
            }
        });

        bar.setText("Bar");
        bar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        bar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                barMouseClicked(evt);
            }
        });

        factuur.setText("Factuur");
        factuur.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        factuur.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                factuurMouseClicked(evt);
            }
        });

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/size32/Apps-session-logout-icon.png"))); // NOI18N
        jLabel9.setText("logout");
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(home)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(leden)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(activiteit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(factuur)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(home)
                    .addComponent(leden)
                    .addComponent(activiteit)
                    .addComponent(bar)
                    .addComponent(factuur))
                .addContainerGap())
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel_CategoryList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel_ProductList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel_bestelling, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel_bestelling, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jPanel_ProductList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel_CategoryList, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked

        TreePath tp = jTree1.getPathForLocation(evt.getX(), evt.getY());
        if (tp != null) {

            System.out.println(tp.toString());
            if (tp.toString().equalsIgnoreCase("[Categorie, food, tostis]")) {
                jPanel_ProductList.removeAll();
                addProduct(2);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, food, dranken]")) {
                jPanel_ProductList.removeAll();
                addProduct(3);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, food, broodjes]")) {
                jPanel_ProductList.removeAll();
                addProduct(1);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, non-food, judo]")) {
                jPanel_ProductList.removeAll();
                addProduct(4);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, non-food, karate]")) {
                jPanel_ProductList.removeAll();
                addProduct(5);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, non-food, jiu-jitsu]")) {
                jPanel_ProductList.removeAll();
                addProduct(6);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, non-food, merchandising]")) {
                jPanel_ProductList.removeAll();
                addProduct(7);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, faciliteit, faciliteiten]")) {
                jPanel_ProductList.removeAll();
                addProduct(9);
                jPanel_ProductList.repaint();
            } else if (tp.toString().equalsIgnoreCase("[Categorie, cursus, cursussen]")) {
                jPanel_ProductList.removeAll();
                addProduct(8);
                jPanel_ProductList.repaint();
            }else if (tp.toString().equalsIgnoreCase("[Categorie, food, snacks]")) {
                jPanel_ProductList.removeAll();
                addProduct(10);
                jPanel_ProductList.repaint();
            } else {
                System.out.println("you pressed nothing");
            }

        }
    }//GEN-LAST:event_jTree1MouseClicked

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if (jCheckBox1.isSelected()) {
            jCheckBox2.setSelected(false);
            jCheckBox3.setSelected(false);
            vestiging = 1;
            jPanel_ProductList.repaint();
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        if (jCheckBox2.isSelected()) {
            jCheckBox1.setSelected(false);
            jCheckBox3.setSelected(false);
            vestiging = 2;
            jPanel_ProductList.repaint();
        }
    }//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed


        if (jCheckBox3.isSelected()) {
            jCheckBox2.setSelected(false);
            jCheckBox1.setSelected(false);
            vestiging = 3;
            jPanel_ProductList.repaint();
        }
    }//GEN-LAST:event_jCheckBox3ActionPerformed

    private void homeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_homeMouseClicked
        // TODO add your handling code here:
        BarApplication.getInstance().showPanel(new Home(login));
    }//GEN-LAST:event_homeMouseClicked

    private void ledenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ledenMouseClicked
        BarApplication.getInstance().showPanel(new MemberOverview(login));
    }//GEN-LAST:event_ledenMouseClicked

    private void activiteitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_activiteitMouseClicked

            BarApplication.getInstance().showPanel(new GroupActivityOverview(login));

    }//GEN-LAST:event_activiteitMouseClicked

    private void barMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_barMouseClicked

        if (evt != null) {
            BarApplication.getInstance().showPanel(new shopping_bar(login));
        }
    }//GEN-LAST:event_barMouseClicked

    private void factuurMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_factuurMouseClicked
        if (evt != null) {
            BarApplication.getInstance().showPanel(new FactuurOverview(login));
        }
    }//GEN-LAST:event_factuurMouseClicked

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked
        // TODO add your handling code here:
        BarApplication.getInstance().showPanel(new LoginScreen());
    }//GEN-LAST:event_jLabel9MouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel activiteit;
    private javax.swing.JLabel bar;
    private javax.swing.JLabel factuur;
    private javax.swing.JLabel home;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    public javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel_CategoryList;
    public javax.swing.JPanel jPanel_ProductList;
    private javax.swing.JPanel jPanel_bestelling;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree jTree1;
    private javax.swing.JLabel leden;
    // End of variables declaration//GEN-END:variables

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        //blank
    }

    public void mouseReleased(MouseEvent e) {
        //blank
    }

    public void mouseEntered(MouseEvent e) {
        //blank
    }

    public void mouseExited(MouseEvent e) {
        //blank
    }

    public void actionPerformed(ActionEvent event) {
        String product_id = ((JButton) event.getSource()).getName();

        System.out.println(product_id);

        //     if (product_id.contains("cursus")) {
        //        Product product = BarApplication.getQueryManager().getCourse(Integer.parseInt(product_id));
        //       BarApplication.getBasket().addProduct(product);
        //      basketDisplay();
        //     jLabel1.repaint();

        if (!product_id.equals("pay") && !product_id.equals("cancel") && !product_id.contains("less")) {
            Product product = BarApplication.getQueryManager().getProduct(Integer.parseInt(product_id));
            BarApplication.getBasket().addProduct(product);
            basketDisplay();
            jLabel1.repaint();
        } else if (product_id.equals("pay")) {
            System.out.println("pay");
            BarApplication.getInstance().showPanel(new view.Payment(login, vestiging));
        } else if (product_id.equals("cancel")) {
            System.out.println("cancel");
            BarApplication.getBasket().empty();
            basketDisplay();
            jLabel1.repaint();
        } else if (product_id.contains("less")) {
            System.out.println(product_id);
            product_id = product_id.replaceFirst("less", "");
            Product product = BarApplication.getQueryManager().getProduct(Integer.parseInt(product_id));
            BarApplication.getBasket().removeProduct(product);
            basketDisplay();
            jLabel1.repaint();
        }
    }
}
